package com.ce.pms.system.custservice.service;

import java.util.List;

import org.hibernate.exception.ConstraintViolationException;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.dao.DataIntegrityViolationException;

import com.ce.pms.DBUnitTool;
import com.ce.pms.base.vo.SearchVO;
import com.ce.pms.exception.BusinessException;
import com.ce.pms.system.custservice.dao.ISignReadingRuleDao;
import com.ce.pms.system.custservice.model.SignReadingRuleDO;
import com.ce.pms.system.custservice.service.ISignReadingRuleService;
import com.ce.pms.system.custservice.vo.SignReadingRuleVO;
/**
 * 功能描述: 阅签规则维护service单元测试类
 * <p>版权所有：中企动力
 * <p>未经本公司许可，不得以任何方式复制或使用本程序任何部分
 *
 * @author  胡煦
 * Create on:2008-12-17
 * Edit author:
 * Edit on:
 * 修改原因：

 */
public class SignReadingRuleServiceImplT extends DBUnitTool {
	/**
	 * 方法描述: 阅签规则列表查询test方法
	 * @author 胡煦
	 * Create on:2008-12-16
	 * @param name
	 * @return List<SignReadingRuleVO>
	 * Edit author:
	 * Edit on:
	 * 修改原因：
	 */
	@Test
	public void testQueryAllSignReadingRuleByPage() {
		SearchVO searchVO = new SearchVO("name desc",1, 5);
		List list = signReadingRuleService.queryAllSignReadingRuleByPage(searchVO).getResult();
		Assert.assertNotNull("断言不为空",list);
	}
	/**
	 * 方法描述: 阅签规则列表查询方法(根据序号升序排序，如果为空则在最后)
	 * @author 胡煦
	 * Create on:2008-12-16
	 * @param name
	 * @return List<SignReadingRuleVO>
	 * Edit author:
	 * Edit on:
	 * 修改原因：
	 */
	@Test
	public void testGetSignReadingRuleList(){
		List list = signReadingRuleService.getSignReadingRuleList();
		Assert.assertNotNull("断言不为空",list);
	}
	/**
	 * 方法描述: 阅签规则增加test方法
	 *
	 * @author 胡煦 Create on:2008-12-16
	 * @param SignReadingRuleVO
	 * @return SignReadingRuleVO Edit author: Edit on: 修改原因：
	 */
	@Test
	public void testAddSignReadingRule() {
		SignReadingRuleVO readingRuleVO = new SignReadingRuleVO();
		readingRuleVO.setCreator(1l);
		readingRuleVO.setCustServEventKindId(1l);
		readingRuleVO.setEmergencyDegreeId(1l);
		readingRuleVO.setName("测试一");
		readingRuleVO.setValidity("1");
		try {
			readingRuleVO = signReadingRuleService.addSignReadingRule(readingRuleVO);
			Assert.assertNotNull("断言不为空",readingRuleVO.getKeyword());
		} catch (BusinessException e) {
			e.printStackTrace();
			super.dealBusinessException(e, "custservice:system_name_exist_exception");
		}
	}
	/**
	 * 方法描述: 阅签规则删除test方法
	 *
	 * @author 胡煦 Create on:2008-12-16
	 * @param SignReadingRuleVO
	 * @return SignReadingRuleVO Edit author: Edit on: 修改原因：
	 */
	@Test
	public void testDeleteSignReadingRule() {

		try {
			Long readingRuleId = 1l;
			signReadingRuleService.deleteSignReadingRule(readingRuleId);
			SignReadingRuleDO readingRuleDO = signReadingRuleDao.findById(readingRuleId);
			Assert.assertNull("断言为空",readingRuleDO);

		} catch (ConstraintViolationException e) {
			e.printStackTrace();
			super.dealException(e);
		}catch (DataIntegrityViolationException e) {
			e.printStackTrace();
			super.dealException(e);
		}catch (BusinessException e) {
			e.printStackTrace();
			super.dealBusinessException(e, "custservice:system_delete_inused_exception");
		}
	}
	/**
	 * 方法描述: 阅签规则修改test方法
	 *
	 * @author 胡煦 Create on:2008-12-16
	 * @param readingRuleId
	 * @return boolean Edit author: Edit on: 修改原因：
	 */
	@Test
	public void testEditSignReadingRule() {
		SignReadingRuleVO readingRuleVO = new SignReadingRuleVO();
		readingRuleVO.setKeyword(5l);
		readingRuleVO.setCreator(1l);
		readingRuleVO.setCustServEventKindId(1l);
		readingRuleVO.setEmergencyDegreeId(1l);
		readingRuleVO.setName("测试二");
		readingRuleVO.setValidity("1");
		readingRuleVO.setModifier(1l);
		try {
			readingRuleVO = signReadingRuleService.editSignReadingRule(readingRuleVO);
			Assert.assertEquals("测试二", readingRuleVO.getName());
		} catch (BusinessException e) {
			e.printStackTrace();
			super.dealBusinessException(e, "custservice:system_name_exist_exception");
		}
	}
	/**
	 * 功能描述:校验阅签规则名字是否存在test方法<br>
	 * 注：新建判断name的唯一性时，oldId传为null；修改判断name的唯一性时，则需要传入本身的ID<br>
	 * @param name
	 * @param id
	 * @return
	 * Create author:胡煦
	 * Create on:2008-7-18
	 * Edit author:
	 * Edit on:
	 * Why:
	 */
	@Test
	public void testCheckSignReadingRuleByName(){

		try {
			signReadingRuleService.checkSignReadingRuleByName("测试二", null);
		} catch (BusinessException e) {
			e.printStackTrace();
			super.dealBusinessException(e, "custservice:system_name_exist_exception");
		}
	}
	static private ISignReadingRuleService signReadingRuleService;
	static private ISignReadingRuleDao signReadingRuleDao;
	/**
    *
    * 功能描述:   <br>
    *
    * Create author：胡煦  <br>
    * Create on:2008-12-17  <br>
    * Edit author：  <br>
    * Edit on:    <br>
    * Why:     <br>
    */
	@BeforeClass
	public static void initSignReadingRule(){
		if (signReadingRuleService == null) {
			signReadingRuleService = (ISignReadingRuleService)DBUnitTool.applicationContext.getBean("signReadingRuleService");
		}
		if (signReadingRuleDao == null) {
			signReadingRuleDao = (ISignReadingRuleDao)DBUnitTool.applicationContext.getBean("signReadingRuleDao");
		}
	}
}
